export function delay(interval = 0) {
    return new Promise((resolve) => {
        let timer = setTimeout((_) => {
            clearTimeout(timer);
            resolve();
        }, interval);
    });
}

export function readFile(file) {
    return new Promise((resolve) => {
        const reader = new FileReader();
        // 二进制
        // reader.readAsBinaryString(file);
        reader.readAsArrayBuffer(file);
        reader.onload = (e) => {
            resolve(e.target.result);
        };
    });
}

export const character = {
    name: {
        text: '姓名',
        type: 'string'
    },
    phone: {
        text: '电话',
        type: 'string'
    }
};

export function formatTime(str, tpl) {
    let arr = str.match(/\d+/g).map((item) => {
        return item.length < 2 ? '0' + item : item;
    });
    tpl = tpl || '{0}年{1}月{2}日 {3}时{4}分{5}秒';
    return tpl.replace(/\{(\d+)\}/g, (_, group) => {
        return arr[group] || '00';
    });
}
